import java.util.*;

public class Practice3 {
    //https://www.nowcoder.com/practice/1718131e719746e9a56fb29c40cc8f95?tpId=230&tqId=39753&ru=/exam/oj
    //考察简单的动态规划, 因为不是升序或降序, 不可以使用滑动窗口
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = sc.nextInt();
        }

        int[] f = new int[n + 1];
        int max = Integer.MIN_VALUE;
        for(int i = 1;i <= n;i++){
            f[i] = Math.max(f[i - 1] + arr[i - 1],arr[i - 1]);
            max = Math.max(f[i],max);
        }
        System.out.println(max);
    }
}
